#include <allegro.h>
#include <stdio.h>
#include "gang.h"

int main () {

char chemin_background[50]="/home/ines/jeu/images/etage1.bmp";

	BITMAP *Buffer;
	BITMAP *Background=NULL;
        
        Gangsters gang;
        int compteur, last_direction;

        allegro_init();
	if (install_keyboard() == -1) {
		allegro_message("Error! %s", allegro_error);
		return (-1);
	}
	set_color_depth(16);
	if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, GFX_W, GFX_H, 0, 0) != 0) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
		allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
		return (1);
	}
        
        Buffer = create_bitmap(SCREEN_W, SCREEN_H);
	Background = load_background_bmp(Background);
	draw_background(Background,Buffer);
    
	load_gangsters(&gang);
           
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
	compteur = 0;
	init_gangsters(&gang);
	draw_background(Background,Buffer);
		blit(Background, Buffer, 0, 0, 0, 0, SCREEN_W, SCREEN_H);


        while (!key[KEY_ESC]) {
		
		clear_bitmap(Buffer);
		draw_background(Background,Buffer);
		draw_gangsters(gang,Buffer,compteur);
              
	blit(Buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
move_gangsters(&gang,&compteur,Background);
		
	if (compteur == 10000)
	compteur = 0;
	}

	readkey();
	destroy_gangsters(&gang);
	destroy_background(Background);
	destroy_bitmap(Buffer);
	return (0);


}
END_OF_MAIN();
